package com.example.mvp.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;

public abstract class BaseAdapter<DATA> extends RecyclerView.Adapter<BaseViewHolder> {
    protected List<DATA> datas;
    protected Context context;
    protected LayoutInflater layoutInflater;
    private int layoutId;

    public BaseAdapter(List<DATA> datas, Context context,  int layoutId) {
        this.datas = datas;
        this.context = context;
        layoutInflater= layoutInflater.from(context);
        this.layoutId = layoutId;
    }

    @NonNull
    @Override
    public BaseViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new BaseViewHolder(layoutInflater.inflate(layoutId,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull BaseViewHolder holder, int position) {
        bindData(holder,datas.get(position));
    }

    protected abstract void bindData(BaseViewHolder holder, DATA data);

    @Override
    public int getItemCount() {
        return datas.size();
    }
}
